C
C fintrf.h	- MATLAB/FORTRAN interface header file. This file
C		  contains the declaration of the pointer type needed
C		  by the MATLAB/FORTRAN interface.
C
C Copyright (c) 1993-94 by The MathWorks, Inc.
C $Revision: 1.4 $  $Date: 1994/12/28 19:19:45 $
C----------------------------------------------------------------------
C





C
C DC3DG.F - Gateway function for DC3D.F
C
C This is an example of the FORTRAN code required for interfacing
C a .MEX file to MATLAB.
C
C This subroutine is the main gateway to MATLAB.  When a MEX function
C  is executed MATLAB calls the USRFCN subroutine in the corresponding
C  MEX file.  
C
C $Revision: 1.2 $
C
      SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)

      INTEGER PLHS(*), PRHS(*)
      INTEGER NLHS, NRHS
C
      INTEGER MXCREATEFULL, MXGETPR
C     INTEGER MXGETM, MXGETN
C
C KEEP THE ABOVE SUBROUTINE, ARGUMENT, AND FUNCTION DECLARATIONS FOR USE
C IN ALL YOUR FORTRAN MEX FILES.
C---------------------------------------------------------------------
C
      INTEGER ALPHAP, XP, YP, ZP, DEPTHP, DIPP,
     *        AL1P, AL2P, AW1P, AW2P, DISL1P, DISL2P, DISL3P,
     *        UXP, UYP, UZP, UXXP, UYXP, UZXP, UXYP, UYYP, UZYP,
     *        UXZP, UYZP, UZZP, IRETP
      REAL*8 RALPHAP, RXP, RYP, RZP, RDEPTHP, RDIPP,
     *       RAL1P, RAL2P, RAW1P, RAW2P, RDISL1P, RDISL2P, RDISL3P,
     *       RUXP, RUYP, RUZP, RUXXP, RUYXP, RUZXP, RUXYP, RUYYP,
     *       RUZYP, RUXZP, RUYZP, RUZZP, RIRETP

C
C CHECK FOR PROPER NUMBER OF ARGUMENTS
C
      IF (NRHS .NE. 13) THEN
        CALL MEXERRMSGTXT('DC3D requires 13 input arguments')
      ELSEIF (NLHS .GT. 13) THEN
        CALL MEXERRMSGTXT('DC3D requires at most 13 output arguments')
      ENDIF
C
C CREATE A MATRIX FOR RETURN ARGUMENT
C
      PLHS(1) = MXCREATEFULL(1,1,0)
      PLHS(2) = MXCREATEFULL(1,1,0)
      PLHS(3) = MXCREATEFULL(1,1,0)
      PLHS(4) = MXCREATEFULL(1,1,0)
      PLHS(5) = MXCREATEFULL(1,1,0)
      PLHS(6) = MXCREATEFULL(1,1,0)
      PLHS(7) = MXCREATEFULL(1,1,0)
      PLHS(8) = MXCREATEFULL(1,1,0)
      PLHS(9) = MXCREATEFULL(1,1,0)
      PLHS(10) = MXCREATEFULL(1,1,0)
      PLHS(11) = MXCREATEFULL(1,1,0)
      PLHS(12) = MXCREATEFULL(1,1,0)
      PLHS(13) = MXCREATEFULL(1,1,0)
C
C ASSIGN POINTERS TO THE VARIOUS PARAMETERS
C
      UXP = MXGETPR(PLHS(1))
      UYP = MXGETPR(PLHS(2))
      UZP = MXGETPR(PLHS(3))
      UXXP = MXGETPR(PLHS(4))
      UYXP = MXGETPR(PLHS(5))
      UZXP = MXGETPR(PLHS(6))
      UXYP = MXGETPR(PLHS(7))
      UYYP = MXGETPR(PLHS(8))
      UZYP = MXGETPR(PLHS(9))
      UXZP = MXGETPR(PLHS(10))
      UYZP = MXGETPR(PLHS(11))
      UZZP = MXGETPR(PLHS(12))
      IRETP = MXGETPR(PLHS(13))
C
      ALPHAP = MXGETPR(PRHS(1))
      XP = MXGETPR(PRHS(2))
      YP = MXGETPR(PRHS(3))
      ZP = MXGETPR(PRHS(4))
      DEPTHP = MXGETPR(PRHS(5))
      DIPP = MXGETPR(PRHS(6))
      AL1P = MXGETPR(PRHS(7))
      AL2P = MXGETPR(PRHS(8))
      AW1P = MXGETPR(PRHS(9))
      AW2P = MXGETPR(PRHS(10))
      DISL1P = MXGETPR(PRHS(11))
      DISL2P = MXGETPR(PRHS(12))
      DISL3P = MXGETPR(PRHS(13))
C
C COPY RIGHT HAND ARGUMENTS TO LOCAL ARRAYS OR VARIABLES
      CALL MXCOPYPTRTOREAL8(ALPHAP, RALPHAP, 1)
      CALL MXCOPYPTRTOREAL8(XP, RXP, 1)
      CALL MXCOPYPTRTOREAL8(YP, RYP, 1)
      CALL MXCOPYPTRTOREAL8(ZP, RZP, 1)
      CALL MXCOPYPTRTOREAL8(DEPTHP, RDEPTHP, 1)
      CALL MXCOPYPTRTOREAL8(DIPP, RDIPP, 1)
      CALL MXCOPYPTRTOREAL8(AL1P, RAL1P, 1)
      CALL MXCOPYPTRTOREAL8(AL2P, RAL2P, 1)
      CALL MXCOPYPTRTOREAL8(AW1P, RAW1P, 1)
      CALL MXCOPYPTRTOREAL8(AW2P, RAW2P, 1)
      CALL MXCOPYPTRTOREAL8(DISL1P, RDISL1P, 1)
      CALL MXCOPYPTRTOREAL8(DISL2P, RDISL2P, 1)
      CALL MXCOPYPTRTOREAL8(DISL3P, RDISL3P, 1)
C
C DO THE ACTUAL COMPUTATIONS IN A SUBROUTINE
C       CREATED ARRAYS.  
C
      CALL DC3D(RALPHAP, RXP, RYP, RZP, RDEPTHP, RDIPP,
     *     RAL1P, RAL2P, RAW1P, RAW2P, RDISL1P, RDISL2P,
     *     RDISL3P, RUXP, RUYP, RUZP, RUXXP, RUYXP,
     *     RUZXP, RUXYP, RUYYP, RUZYP,RUXZP, RUYZP,
     *     RUZZP, RIRETP)
C
C COPY OUTPUT WHICH IS STORED IN LOCAL ARRAY TO MATRIX OUTPUT
      CALL MXCOPYREAL8TOPTR(RUXP, UXP, 1)
      CALL MXCOPYREAL8TOPTR(RUYP, UYP, 1)
      CALL MXCOPYREAL8TOPTR(RUZP, UZP, 1)
      CALL MXCOPYREAL8TOPTR(RUXXP, UXXP, 1)
      CALL MXCOPYREAL8TOPTR(RUYXP, UYXP, 1)
      CALL MXCOPYREAL8TOPTR(RUZXP, UZXP, 1)
      CALL MXCOPYREAL8TOPTR(RUXYP, UXYP, 1)
      CALL MXCOPYREAL8TOPTR(RUYYP, UYYP, 1)
      CALL MXCOPYREAL8TOPTR(RUZYP, UZYP, 1)
      CALL MXCOPYREAL8TOPTR(RUXZP, UXZP, 1)
      CALL MXCOPYREAL8TOPTR(RUYZP, UYZP, 1)
      CALL MXCOPYREAL8TOPTR(RUZZP, UZZP, 1)
      CALL MXCOPYREAL8TOPTR(RIRETP, IRETP, 1)
C
      RETURN
      END
